/**
 * 将字符串中的数值和单位分离
 * @param str
 * @example splitValueAndUnit('12px') // {number: 12, unit: 'px'}
 * @example splitValueAndUnit('12') // {number: 12, unit: ''}
 * @example splitValueAndUnit('10.5px') // {number: 10.5, unit: 'px'}
 * @returns {{number: number, unit: string}}
 */
export function splitValueAndUnit(str: string) {
  const numberRegex = /^(\d+(?:\.\d+)?)/;
  const numberMatch = str.match(numberRegex);
  let number = null;
  if (numberMatch) {
    number = parseFloat(numberMatch[0]);
  }
  const unit = str.replace(numberRegex, '').trim();
  return { number, unit };
}